# -*-coding:utf-8-*-
import random
import time

from django.core.mail import send_mail

from mock_2021.settings import EMAIL_FROM
from users.models import EmailVerifyRecord


def generate_code(code_length):
    #  可加时间戳+加长长度+
    chars = 'QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm0123456789'
    return ''.join(random.sample(chars,code_length))


def send_cus_mail(email,type,*args):
    code = generate_code(10)
    email_record = EmailVerifyRecord()
    email_record.code = code
    email_record.email = email
    email_record.send_type = type
    email_record.save()

    email_title = ''
    email_body = ''
    if type == 'register':
        email_title = '在线激活链接'
        email_body = f'请点击下面链接以激活账号 http://127.0.0.1:8000/active/{code}'
        send_status = send_mail(email_title,email_body,EMAIL_FROM,[email])
        if send_status:
            pass

